<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: yangweijie <yangweijiester@gmail.com> <code-tech.diandian.com>
// +----------------------------------------------------------------------

namespace Help\Model;

use Think\Model;

/**
 * Class HelpEvaluateModel  评价模型
 * @package Help\Model
 * @author:xjw129xjt xjt@ourstu.com
 */
class HelpEvaluateModel extends Model
{

    protected $tableName = 'help_evaluate';

    protected $_auto = array(
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('update_time', NOW_TIME, self::MODEL_BOTH),
        array('status', '1', self::MODEL_INSERT),
    );

    protected $insertFields = 'help_id,uid,to_uid,content,attach_ids,type,punctual,trustworthy,technique,attitude';
    protected $updateFields = 'help_id,uid,to_uid,content,attach_ids,type,punctual,trustworthy,technique,attitude';

    public function addEvaluate($data)
    {
        $data = $this->create($data);
        $data['uid']=is_login();
        $res = $this->add($data);
        return $res;
    }

    public function getEvaluate($map=''){
        $map['status'] =1;
        $evaluate = $this->where($map)->order('create_time desc')->select();
        return $evaluate;
    }

    public function getEvaluateById($id){
        $evaluate = S('help_evaluate_'.$id);
        if(empty($evaluate)){
            $evaluate = $this->where(array('id'=>$id,'status'=>1))->find();
            S('help_evaluate_'.$id,$evaluate);
        }
        !empty($evaluate) && $evaluate['user'] =query_user(array('uid', 'username', 'nickname', 'space_url', 'space_link', 'avatar64','avatar128', 'rank_html', 'signature','address','doing','fans'), $evaluate['uid']);
        !empty($evaluate) && $evaluate['to_user'] =query_user(array('uid', 'username', 'nickname', 'space_url', 'space_link', 'avatar64','avatar128', 'rank_html', 'signature','address','doing','fans'), $evaluate['to_uid']);
        return $evaluate;
    }


    public function getEvaluateCount($map=''){
        $map['status'] =1;
        $evaluate = $this->where($map)->order('create_time desc')->count();
        return $evaluate;
    }


}